﻿using System.Collections.Generic;

namespace Jayden.Dll.Core.Logging
{
	public sealed class LogManager
	{

		private static LogManager m_Instance;
		public static LogManager Instance
		{
			get
			{
				if (m_Instance == null)
				{
					lock (typeof(LogManager))
					{
						if (m_Instance == null)
						{
							m_Instance = new LogManager();
						}
					}
				}
				return m_Instance;
			}
		}

		private Dictionary<string, Logger> m_LoggersByName = new Dictionary<string,Logger>();

		protected LogManager() { }

		public bool AddLogger(Logger logger)
		{
			lock (this)
			{
				if (m_LoggersByName.ContainsKey(logger.Name))
					return false;
				m_LoggersByName.Add(logger.Name, logger);
				return true;
			}
		}

		public Logger GetLogger(string name)
		{
			Logger logger = null;
			if (m_LoggersByName.TryGetValue(name, out logger))
				return logger;
			return null;
		}

		public IEnumerable<string> GetLoggerNames() { return new List<string>(m_LoggersByName.Keys); }

	}
}
